<template>
  <div class="app-container home">
    <div ref="lineAverageScore" style="width: 100%; height: 400px;"></div>
    <div ref="maleFemaleRatio" style="width: 100%; height: 400px;"></div>
    <div ref="lineChartDeptUserCount" style="width: 100%; height: 400px;"></div>
  </div>
</template>

<script>

import * as echarts from 'echarts';
import { findDeptUserCount } from "@/api/system/dept";
import { initLineAverageScore } from "@/api/system/performance";
import { maleFemaleRatio } from "@/api/system/user";

export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.7",
      dataLine: [],
      xAxisLine: [],
      sectionDataLine: [],
      sectionXAxisLine: [],
      maleFemaleRatioDataLine: [],
      maleFemaleRatioXAxisLine: []
    };
  },
  mounted() {
    this.initLineChartDeptUserCount();
    this.initLineAverageScore();
    this.maleFemaleRatio()
  },
  methods: {
    initLineChartDeptUserCount() {
      const chartDom = this.$refs.lineChartDeptUserCount;
      const myChart = echarts.init(chartDom);
      findDeptUserCount(null).then(response => {
        const deptList = response.data
        for (let i = 0; i < deptList.length; i++){
          const dept = deptList[i]
          this.dataLine.push(dept.qty)
          this.xAxisLine.push(dept.deptName)
        }
        const option = {
          title: {
            text: '人员分布图'
          },
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            type: 'category',
            data: this.xAxisLine
          },
          yAxis: {
            type: 'value'
          },
          series: [{
            data: this.dataLine,
            type: 'line'
          }]
        };
        myChart.setOption(option);
      })
    },
    initLineAverageScore() {
      const chartDom = this.$refs.lineAverageScore;
      const myChart = echarts.init(chartDom);
      initLineAverageScore(null).then(response => {
        const performanceList = response.data
        for (let i = 0; i < performanceList.length; i++){
          const performance = performanceList[i]
          this.sectionDataLine.push(performance.qty)
          this.sectionXAxisLine.push(performance.section)
        }
        const option = {
          title: {
            text: '分数区间图'
          },
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            type: 'category',
            data: this.sectionXAxisLine
          },
          yAxis: {
            type: 'value'
          },
          series: [{
            data: this.sectionDataLine,
            type: 'line'
          }]
        };
        myChart.setOption(option);
      })
    },
    maleFemaleRatio() {
      const chartDom = this.$refs.maleFemaleRatio;
      const myChart = echarts.init(chartDom);
      maleFemaleRatio(null).then(response => {
        const userList = response.data
        for (let i = 0; i < userList.length; i++){
          const user = userList[i]
          this.maleFemaleRatioDataLine.push(user.qty)
          this.maleFemaleRatioXAxisLine.push(user.sex)
        }
        const option = {
          title: {
            text: '男女比例'
          },
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            type: 'category',
            data: this.maleFemaleRatioXAxisLine
          },
          yAxis: {
            type: 'value'
          },
          series: [{
            data: this.maleFemaleRatioDataLine,
            type: 'line'
          }]
        };
        myChart.setOption(option);
      })
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

